package com.extra;

import java.util.List;

public class Solution24 {
    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode pre = dummy;
        ListNode cur = dummy;
        ListNode q;
        while (cur.next != null && cur.next.next != null) {
            cur = cur.next;
            q = cur.next;
            cur.next = q.next;
            q.next = cur;
            pre.next = q;
            pre = cur;
        }
        return dummy.next;
    }
}

class ListNode {
    int val;
    ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}
